from point import Point


class Command:
    def __init__(self):
        self.__point = Point()
        self.__direction = ''

    @staticmethod
    def parse(raw_command):
        command = Command()
        if len(raw_command) != 3:
            return command, True
        point, err = Point.parse(raw_command[:2])
        if err:
            return command, True
        if not raw_command[2] in ['V', 'H']:
            return command, True
        command.set_point(point)
        command.set_direction(raw_command[2])
        return command, False

    @staticmethod
    def to_points(cmd, length) -> list:
        point = cmd.get_point()
        points = [point]
        if cmd.get_direction() == 'H':
            for i in range(1, length):
                points.append(Point(point.get_x(), point.get_y() + i))
        else:
            for i in range(1, length):
                points.append(Point(point.get_x() + i, point.get_y()))
        return points

    # 设置point属性
    def set_point(self, point) -> None:
        self.__point = point

    # 返回point属性
    def get_point(self) -> Point:
        return self.__point

    # 设置direction属性
    def set_direction(self, direction) -> None:
        self.__direction = direction

    # 返回direction属性
    def get_direction(self) -> str:
        return self.__direction


if __name__ == '__main__':
    a, b = Command.parse('A4V')
    print(a.get_point().get_x(), a.get_point().get_y(), a.get_direction(), b)
    c = Command.to_points(a, 4)
    for x in c:
        print(x.get_x(), x.get_y())
